int do_chmod(char* args)
{
	char* mode, *file;
	char fullPath[MAX_PATH_LENGTH];
	int usr, grp, oth;
	LOC fileLocation;
	MINODE* fileInode;
	
	if (strrchr(args, ' ') == 0)
	{
		printf("Not enough args\n\n");
		return -1;
	}
	
	mode = strtok(args, " ");
	file = strtok(0, " \n");
	
	if (strlen(mode) != 3)
	{
		printf("Incorrect mode argument\n\n");
		return -1;
	}
	
	if (((mode[0] < '0') || (mode[0] > '7')) ||
		((mode[1] < '0') || (mode[1] > '7')) ||
		((mode[2] < '0') || (mode[2] > '7')))
	{
		printf("Invalid mode specified\n\n");
		return -1;
	}
	
	usr = mode[0] - '0';
	grp = mode[1] - '0';
	oth = mode[2] - '0';
	
	if (file[0] != '/')
	{
		char tmp[MAX_PATH_LENGTH];
		get_pwd_name(runningProc->cwd, tmp);
		strcat(tmp, file);
		strcpy(fullPath, tmp);
	}
	else
		strcpy(fullPath, file);
	
	fileLocation = get_inode_number(fullPath);
	if (fileLocation.inodeNum == 0)
		return -1;
		
	fileInode = get_inode(fileLocation.deviceHandle, fileLocation.inodeNum);
	if (fileInode == 0)
		return -1;
		
	switch(usr)
	{
		case 0:	{
			fileInode->inode.i_mode = 0;
		} break;
		
		case 1:	{
			fileInode->inode.i_mode = IACCESS_USR_EXEC;
		} break;
		
		case 2:	{
			fileInode->inode.i_mode = IACCESS_USR_WRITE;
		} break;
		
		case 3:	{
			fileInode->inode.i_mode = IACCESS_USR_EXEC | IACCESS_USR_WRITE;
		} break;
		
		case 4:	{
			fileInode->inode.i_mode = IACCESS_USR_READ;
		} break;
		
		case 5:	{
			fileInode->inode.i_mode = IACCESS_USR_READ | IACCESS_USR_EXEC;
		} break;
		
		case 6:	{
			fileInode->inode.i_mode = IACCESS_USR_READ | IACCESS_USR_WRITE;
		} break;
		
		case 7:	{
			fileInode->inode.i_mode = IACCESS_USR_EXEC | IACCESS_USR_WRITE | IACCESS_USR_READ;
		} break;
	}
	
	switch(grp)
	{
		case 1:	{
			fileInode->inode.i_mode |= IACCESS_GRP_EXEC;
		} break;
		
		case 2:	{
			fileInode->inode.i_mode |= IACCESS_GRP_WRITE;
		} break;
		
		case 3:	{
			fileInode->inode.i_mode |= IACCESS_GRP_EXEC | IACCESS_GRP_WRITE;
		} break;
		
		case 4:	{
			fileInode->inode.i_mode |= IACCESS_GRP_READ;
		} break;
		
		case 5:	{
			fileInode->inode.i_mode |= IACCESS_GRP_READ | IACCESS_GRP_EXEC;
		} break;
		
		case 6:	{
			fileInode->inode.i_mode |= IACCESS_GRP_READ | IACCESS_GRP_WRITE;
		} break;
		
		case 7:	{
			fileInode->inode.i_mode |= IACCESS_GRP_EXEC | IACCESS_GRP_WRITE | IACCESS_GRP_READ;
		} break;
	}
	
	switch(oth)
	{		
		case 1:	{
			fileInode->inode.i_mode |= IACCESS_OTH_EXEC;
		} break;
		
		case 2:	{
			fileInode->inode.i_mode |= IACCESS_OTH_WRITE;
		} break;
		
		case 3:	{
			fileInode->inode.i_mode |= IACCESS_OTH_EXEC | IACCESS_OTH_WRITE;
		} break;
		
		case 4:	{
			fileInode->inode.i_mode |= IACCESS_OTH_READ;
		} break;
		
		case 5:	{
			fileInode->inode.i_mode |= IACCESS_OTH_READ | IACCESS_OTH_EXEC;
		} break;
		
		case 6:	{
			fileInode->inode.i_mode |= IACCESS_OTH_READ | IACCESS_OTH_WRITE;
		} break;
		
		case 7:	{
			fileInode->inode.i_mode |= IACCESS_OTH_EXEC | IACCESS_OTH_WRITE | IACCESS_OTH_READ;
		} break;
	}
	
	fileInode->dirty = true;
	
	put_inode(fileInode);
	
	return 1;
}
